//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _APPS_BUSH_PARSER_ENUMS_H_
#define _APPS_BUSH_PARSER_ENUMS_H_

#include <buola/buola.h>

namespace buola { namespace bush {

enum ETokenizeResult
{
    TOKENIZE_OK,
    TOKENIZE_DEDENT_ERROR,
    TOKENIZE_STRING_ERROR,
    TOKENIZE_EOI_ENCLOSURE,
    TOKENIZE_EOI_STRING,
    TOKENIZE_EOI_LINECONT,
    TOKENIZE_EMPTY,
};

enum EParseResult
{
    PARSE_OK,
    PARSE_INCOMPLETE,
    PARSE_DEDENT_ERROR,
    PARSE_STRING_ERROR,
    PARSE_ERROR,
    PARSE_EMPTY
};

enum ETokenType
{
    TOKENTYPE_WHITESPACE=0x100,
    TOKENTYPE_NUMBER=0x200,
    TOKENTYPE_UNARYOP=0x400,
    TOKENTYPE_BINARYOP=0x800,
    TOKENTYPE_COMPAREOP=0x1000,
    TOKENTYPE_BOOLBINOP=0x2000,
    TOKENTYPE_AUGASSIGNOP=0x4000,
    TOKENTYPE_LITERALKW=0x8000,    
    TOKENTYPE_DOTS=0x10000,
    TOKENTYPE_TINYSTATEMENT=0x20000,
    TOKENTYPE_REDIRECTOP=0x40000,
    TOKENTYPE_PIPELINESEPARATOR=0x80000,
    TOKENTYPE_LISTSEPARATOR=0x100000,
    TOKENTYPE_PIPELINEFINISHER=0x200000,
    TOKENTYPE_OTHERWORDPART=0x400000,
    TOKENTYPE_STRING=0x800000,
    TOKENTYPE_ANYSPACE=0x1000000,
    TOKENTYPE_PARTIALBEGIN=0x2000000,
    TOKENTYPE_ALPHANUM=0x4000000,
    TOKENTYPE_SIMPLEKW=0x8000000,
    TOKENTYPE_COMPKW=0x10000000,
    TOKENTYPE_WORDPART=0x20000000,
    TOKENTYPE_COMMA=0x40000000,
};
DECLARE_ENUM_BITOPS(ETokenType)

enum EToken
{
    TOKEN_INVALID=0,
    //escaped characters
    TOKEN_ESCAPEDCHAR=1|TOKENTYPE_WORDPART,
    //whitespace
    TOKEN_SPACE=2|TOKENTYPE_WHITESPACE|TOKENTYPE_ANYSPACE,
    TOKEN_COMMENT=3|TOKENTYPE_WHITESPACE|TOKENTYPE_ANYSPACE,
    TOKEN_NEWLINE=4|TOKENTYPE_PARTIALBEGIN|TOKENTYPE_ANYSPACE,
    TOKEN_INDENT=5|TOKENTYPE_PARTIALBEGIN|TOKENTYPE_ANYSPACE,
    TOKEN_DEDENT=6|TOKENTYPE_PARTIALBEGIN|TOKENTYPE_ANYSPACE,
    TOKEN_DEDENTERROR=7|TOKENTYPE_PARTIALBEGIN|TOKENTYPE_ANYSPACE,
    //literals
    TOKEN_INTEGER=8|TOKENTYPE_NUMBER|TOKENTYPE_WORDPART,
    TOKEN_FLOAT=9|TOKENTYPE_NUMBER|TOKENTYPE_WORDPART,
    TOKEN_STRING_S=10|TOKENTYPE_WORDPART|TOKENTYPE_STRING,
    TOKEN_STRING_D=11|TOKENTYPE_WORDPART|TOKENTYPE_STRING,
    TOKEN_STRING_I=12|TOKENTYPE_OTHERWORDPART|TOKENTYPE_STRING,
    TOKEN_STRING_TS=13|TOKENTYPE_WORDPART|TOKENTYPE_STRING,
    TOKEN_STRING_TD=14|TOKENTYPE_WORDPART|TOKENTYPE_STRING,
    TOKEN_STRING_TI=15|TOKENTYPE_OTHERWORDPART|TOKENTYPE_STRING,
    TOKEN_STRING_PREFIX=16|TOKENTYPE_WORDPART,
    TOKEN_INCOMPLETESTRING_S=17|TOKENTYPE_WORDPART,
    TOKEN_INCOMPLETESTRING_D=18|TOKENTYPE_WORDPART,
    TOKEN_INCOMPLETESTRING_I=19|TOKENTYPE_WORDPART,
    TOKEN_INCOMPLETESTRING_TS=20|TOKENTYPE_WORDPART,
    TOKEN_INCOMPLETESTRING_TD=21|TOKENTYPE_WORDPART,
    TOKEN_INCOMPLETESTRING_TI=22|TOKENTYPE_WORDPART,
    //python keywords
    TOKEN_KW_NONE=23|TOKENTYPE_LITERALKW|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_CONTINUE=24|TOKENTYPE_TINYSTATEMENT|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_FOR=25|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_COMPKW,
    TOKEN_KW_LAMBDA=26|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_TRY=27|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_COMPKW,
    TOKEN_KW_TRUE=28|TOKENTYPE_LITERALKW|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_DEF=29|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_COMPKW,
    TOKEN_KW_FROM=30|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_NONLOCAL=31|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_WHILE=32|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_COMPKW,
    TOKEN_KW_AND=33|TOKENTYPE_BOOLBINOP|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_DEL=34|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_GLOBAL=35|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_NOT=36|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_WITH=37|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_AS=38|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_ELIF=39|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_IF=40|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_COMPKW,
    TOKEN_KW_OR=41|TOKENTYPE_BOOLBINOP|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_YIELD=42|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_ASSERT=43|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_ELSE=44|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_IMPORT=45|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_PASS=46|TOKENTYPE_TINYSTATEMENT|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_BREAK=47|TOKENTYPE_TINYSTATEMENT|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_EXCEPT=48|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_IN=49|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_RAISE=50|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    TOKEN_KW_FALSE=51|TOKENTYPE_LITERALKW|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_CLASS=52|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_COMPKW,
    TOKEN_KW_FINALLY=53|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_IS=54|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    TOKEN_KW_RETURN=55|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM|TOKENTYPE_SIMPLEKW,
    //enclosers
    TOKEN_LEFT_PAREN=61,
    TOKEN_RIGHT_PAREN=62,
    TOKEN_DOLLAR_PAREN=63,
    TOKEN_LEFT_SQUARE=64|TOKENTYPE_WORDPART,
    TOKEN_RIGHT_SQUARE=65|TOKENTYPE_WORDPART,
    TOKEN_DOLLAR_SQUARE=66,
    TOKEN_LEFT_BRACE=67,
    TOKEN_RIGHT_BRACE=68,
    TOKEN_DOLLAR_BRACE=69,
    //python operators
    TOKEN_OP_COLON=70|TOKENTYPE_WORDPART,
    TOKEN_OP_COMMA=71|TOKENTYPE_COMMA,
    TOKEN_OP_SEMICOLON=72|TOKENTYPE_PARTIALBEGIN,
    TOKEN_OP_PLUS=73|TOKENTYPE_UNARYOP|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_MINUS=74|TOKENTYPE_UNARYOP|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_STAR=75|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_SLASH=76|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_OR=77|TOKENTYPE_BINARYOP|TOKENTYPE_PIPELINESEPARATOR,
    TOKEN_OP_AND=78|TOKENTYPE_BINARYOP|TOKENTYPE_PIPELINEFINISHER,
    TOKEN_OP_LESS=79|TOKENTYPE_COMPAREOP|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_GREATER=80|TOKENTYPE_COMPAREOP|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_EQUAL=81|TOKENTYPE_WORDPART,
    TOKEN_OP_DOT=82|TOKENTYPE_DOTS|TOKENTYPE_WORDPART,
    TOKEN_OP_PERCENT=83|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_XOR=84|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_TILDE=85|TOKENTYPE_UNARYOP|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_AT=86|TOKENTYPE_WORDPART,
    TOKEN_OP_EQEQUAL=87|TOKENTYPE_COMPAREOP|TOKENTYPE_WORDPART,
    TOKEN_OP_NOTEQUALEXC=88|TOKENTYPE_COMPAREOP|TOKENTYPE_WORDPART,
    TOKEN_OP_NOTEQUALLG=89|TOKENTYPE_COMPAREOP,
    TOKEN_OP_LESSEQUAL=90|TOKENTYPE_COMPAREOP,
    TOKEN_OP_LEFTSHIFT=91|TOKENTYPE_BINARYOP|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_GREATEREQUAL=92|TOKENTYPE_COMPAREOP,
    TOKEN_OP_RIGHTSHIFT=93|TOKENTYPE_BINARYOP|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_PLUSEQUAL=94|TOKENTYPE_AUGASSIGNOP|TOKENTYPE_WORDPART,
    TOKEN_OP_MINUSEQUAL=95|TOKENTYPE_AUGASSIGNOP|TOKENTYPE_WORDPART,
    TOKEN_OP_POWER=96|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_STAREQUAL=97|TOKENTYPE_AUGASSIGNOP|TOKENTYPE_WORDPART,
    TOKEN_OP_DOUBLESLASH=98|TOKENTYPE_BINARYOP|TOKENTYPE_WORDPART,
    TOKEN_OP_SLASHEQUAL=99|TOKENTYPE_AUGASSIGNOP|TOKENTYPE_WORDPART,
    TOKEN_OP_OREQUAL=100|TOKENTYPE_AUGASSIGNOP,
    TOKEN_OP_PERCENTEQUAL=101|TOKENTYPE_AUGASSIGNOP|TOKENTYPE_WORDPART,
    TOKEN_OP_ANDEQUAL=102|TOKENTYPE_AUGASSIGNOP,
    TOKEN_OP_XOREQUAL=103|TOKENTYPE_AUGASSIGNOP|TOKENTYPE_WORDPART,
    TOKEN_OP_RARROW=104,
    TOKEN_OP_LEFTSHIFTEQUAL=105|TOKENTYPE_AUGASSIGNOP,
    TOKEN_OP_RIGHTSHIFTEQUAL=106|TOKENTYPE_AUGASSIGNOP,
    TOKEN_OP_POWEREQUAL=107|TOKENTYPE_AUGASSIGNOP|TOKENTYPE_WORDPART,
    TOKEN_OP_DOUBLESLASHEQUAL=108|TOKENTYPE_AUGASSIGNOP|TOKENTYPE_WORDPART,
    TOKEN_OP_ELLIPSIS=109|TOKENTYPE_DOTS|TOKENTYPE_WORDPART,
    //other operators
    TOKEN_OP_EXCLAMATION=110,
    TOKEN_OP_DOLLAR=111,
    TOKEN_OP_QUESTION=112|TOKENTYPE_WORDPART,
    TOKEN_OP_ANDAND=113|TOKENTYPE_LISTSEPARATOR|TOKENTYPE_PARTIALBEGIN,
    TOKEN_OP_OROR=114|TOKENTYPE_LISTSEPARATOR|TOKENTYPE_PARTIALBEGIN,
    TOKEN_OP_ORAND=115|TOKENTYPE_PIPELINESEPARATOR,
    TOKEN_OP_GTAND=116|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_LTAND=117|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_GT3=118|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_LT3=119|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_ANDGT=120|TOKENTYPE_REDIRECTOP,
    TOKEN_OP_GTQUESTION=121|TOKENTYPE_REDIRECTOP,
    //generic identifier or word part
    TOKEN_IDENTIFIER=122|TOKENTYPE_WORDPART|TOKENTYPE_ALPHANUM,
    //python subexpression
    TOKEN_DOLLAR_IDENTIFIER=123,
    TOKEN_INVDIGIT=124|TOKENTYPE_WORDPART,
    TOKEN_WEIRDCHAR=125|TOKENTYPE_WORDPART,
    //line continuation at EOI
    TOKEN_LINECONT=126,
    TOKEN_EOI=127,
    TOKEN_CURSOR=128
};

enum ECompContext
{
    COMP_NONE=0,
    COMP_SHELL=(1<<0),
    COMP_AFTERDOT=(1<<1),
    COMP_ATOM=(1<<2),
    COMP_DOTTEDNAME=(1<<3),
    COMP_IMPORT_FROM=(1<<4),
    COMP_GLOBAL=(1<<5),
    COMP_KEYWORDARG=(1<<6),
    COMP_SIMPLEKW=(1<<7),
    COMP_COMPKW=(1<<8),

    COMP_PYTHON_ANY=COMP_AFTERDOT|COMP_ATOM|COMP_DOTTEDNAME|COMP_IMPORT_FROM|COMP_GLOBAL|
                    COMP_KEYWORDARG|COMP_SIMPLEKW|COMP_COMPKW
};
DECLARE_ENUM_BITOPS(ECompContext)

enum ERunMode
{
    RUN_EXPRESSION,
    RUN_SINGLE,
    RUN_FILE
};

//NOTE: INCOMPLETESTRING has the WORDPART attribute for completion. In any other context, it should not be parsed, 
//since the return value from the tokenizer will not be PARSE_OK.

/*namespace bush*/ } /*namespace buola*/ }

#endif
